package sdk.webview.fmc.com.fmcsdk.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.app.AppManager;
import sdk.webview.fmc.com.fmcsdk.base.BaseActivity;
import sdk.webview.fmc.com.fmcsdk.base.BasePresenter;
import sdk.webview.fmc.com.fmcsdk.bean.OpenMessageEvent;
import sdk.webview.fmc.com.fmcsdk.bean.ReivceMessageEvent;
import sdk.webview.fmc.com.fmcsdk.util.Constant;
import sdk.webview.fmc.com.fmcsdk.util.UserHelper;
import sdk.webview.fmc.com.fmcsdk.util.XLog;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.subscriber.RxBus;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.subscriber.RxBusSubscriber;

public class NoticeActivity extends BaseActivity {


    @Override
    protected int getLayoutId() {
        return R.layout.activity_notice;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        String url = getIntent().getStringExtra(Constant.H5_URL);

        if (!TextUtils.isEmpty(UserHelper.getToken())) {

            XLog.i("存在H5Activity=");
            if (AppManager.isActivityExist(H5Activity.class)) {
//                XLog.i("存在H5Activity=");
//                AppManager.getAppManager().finishActivity(H5Activity.class);
//
                RxBus.getDefault().send(new OpenMessageEvent(url));
//
            }else {
                Intent intents = new Intent();
                intents.putExtra(Constant.H5_TITLE, "推送消息");
                intents.putExtra(Constant.HIDE_HEADER, false);
                //如果消息url为空跳转到待办任务列表
                XLog.i("messageUrl=" +url, context);
                if (TextUtils.isEmpty(url)) {
                    String address = sharedPrefs.getString(Constant.BASE_ADDRESS_URL, "") + "/h5/mytask?accessToken=" + UserHelper.getToken() + "#/myMessage";
                    intents.putExtra(Constant.H5_URL, address);
                } else {
                    intents.putExtra(Constant.H5_URL,url);
                }
                intents.setClass(context, H5Activity.class);
                context.startActivity(intents);
            }

            finish();

        }
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
}